import os
from configs import config, setup_log
from flask import Flask


def create_app(config_name=None):
    app = Flask('flask-student-information-management-system')
    if not config_name:
        config_name = os.getenv('FLASK_CONFIG', 'development')
    setup_log(config_name)
    app.config.from_object(config[config_name])
    register_blueprint(app)
    register_extensions(app)
    register_commands(app)
    return app

def register_blueprint(app):
    from info.index import index_bp
    from info.auth import auth_bp
    app.register_blueprint(auth_bp)
    app.register_blueprint(index_bp)

def register_extensions(app):
     from extensions import login_manager
     from model import db
     
     db.init_app(app)
     login_manager.init_app(app)

def register_commands(app):
    @app.cli.command()
    def create():
        from model import db
        db.create_all()

